package com.securinets.news;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.securinets.R;

public class MyAdapter extends BaseAdapter {
	
    private	ArrayList< Article > articles;
	private LayoutInflater myinflater;
	

	public MyAdapter(Context context, ArrayList<Article> articles) {
		super();
		this.articles = articles;
		this.myinflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		
		return this.articles.size();
	}

	@Override
	public Object getItem(int position) {
		
		return this.articles.get(position);
	}

	@Override
	public long getItemId(int position) {
		
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		
        if (convertView == null) {
        	
        	convertView = myinflater.inflate(R.layout.newsitemlist, null);
        
        	((TextView)convertView.findViewById(R.id.TitreNews)).setText(articles.get(position).titre);
        	((TextView)convertView.findViewById(R.id.DescriptionNews)).setText(articles.get(position).description);
        	//((ImageView)convertView.findViewById(R.id.imageNews)).setImageDrawable(drawable);
        	
        } else {
            
        	
        	((TextView)convertView.findViewById(R.id.TitreNews)).setText(articles.get(position).titre);
        	((TextView)convertView.findViewById(R.id.DescriptionNews)).setText(articles.get(position).description);
        	//((ImageView)convertView.findViewById(R.id.imageNews)).setImageDrawable(drawable);
        }    
        return convertView;
		
	
	}
	
	

}
